import React, { Component } from 'react'

import './Footer.css'

export default class Footer extends Component {
    // 全部勾选
    handleCheckAll = (event) => {
        this.props.checkAllTodo(event.target.checked)
    }
    // 清除已完成任务
    handleCheckAllDone = () => {
        this.props.checkAllDone();
    }
    render() {
        let { todos } = this.props;
        //已完成的个数
        let doneCount = todos.reduce((pre,todo) =>pre + (todo.done? 1 : 0),0)
        //总数
        let total = todos.length;
        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" checked={doneCount === total && total !== 0 ? true : false} onChange={this.handleCheckAll} />
                </label>
                <span>
                    <span>已完成{ doneCount }</span> / 全部{total}
                </span>
                <button className="btn btn-danger" onClick={this.handleCheckAllDone}>清除已完成任务</button>
            </div>
        )
    }
}
